package com.sdleyou.treepro.common.service.impl;

import com.sdleyou.treepro.common.exception.ServiceException;
import com.sdleyou.treepro.common.model.convert.MissionDO2MissionVOConverter;
import com.sdleyou.treepro.common.model.convert.UserMissionDO2UserMissionVOConverter;
import com.sdleyou.treepro.common.model.dao.MissionDO;
import com.sdleyou.treepro.common.model.dao.UserDO;
import com.sdleyou.treepro.common.model.dao.UserMissionDO;
import com.sdleyou.treepro.common.model.dto.MissionDTO;
import com.sdleyou.treepro.common.model.dto.PropDTO;
import com.sdleyou.treepro.common.model.enums.ErrorCodeEnum;
import com.sdleyou.treepro.common.model.vo.MissionVO;
import com.sdleyou.treepro.common.model.vo.PropVO;
import com.sdleyou.treepro.common.model.vo.UserMissionVO;
import com.sdleyou.treepro.common.service.MissionManager;
import com.sdleyou.treepro.common.service.MongoPageManager;
import com.sdleyou.treepro.common.service.UserPropManager;
import com.sdleyou.treepro.common.utils.DateUtil;
import com.sdleyou.treepro.common.utils.IdGen;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class MissionManagerImpl implements MissionManager {

    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private MongoPageManager mongoPageManager;
    @Autowired
    private UserPropManager userPropManager;

    @Override
    public void createTask(MissionDTO missionDTO) {
        MissionDO missionDO = new MissionDO();
        missionDO.setTaskId(IdGen.uuid());
        missionDO.setGmtCreate(DateUtil.getDateline());
        missionDO.setGmtModified(DateUtil.getDateline());
        BeanUtils.copyProperties(missionDTO, missionDO);
        mongoTemplate.insert(missionDO);
    }

    @Override
    public void updateTask(MissionDTO missionDTO, String taskId) {

    }

    /**
     * 获取任务列表
     */
    @Override
    public List<MissionVO> getMissionList() {
        List<MissionDO> missionDOS = mongoTemplate.findAll(MissionDO.class);
        return missionDOS.stream().map(MissionDO2MissionVOConverter::convert).collect(Collectors.toList());
    }
}
